package com.ruoyi.employment.controller;

import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.log.annotation.Log;
import com.ruoyi.common.log.enums.BusinessType;
import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.ruoyi.employment.domain.TComment;
import com.ruoyi.employment.service.ITCommentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.Date;
import java.util.List;

/**
 * 学生评价Controller
 * 
 * @author ruoyi
 * @date 2022-12-24
 */
@RestController
@RequestMapping("/comment")
public class TCommentController extends BaseController
{
    @Autowired
    private ITCommentService tCommentService;

    /**
     * 查询学生评价列表
     */
    @RequiresPermissions("employment:comment:list")
    @GetMapping("/list")
    public TableDataInfo list(TComment tComment)
    {
        startPage();
        List<TComment> list = tCommentService.selectTCommentList(tComment);
        return getDataTable(list);
    }

    /**
     * 导出学生评价列表
     */
    @RequiresPermissions("employment:comment:export")
    @Log(title = "学生评价", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TComment tComment)
    {
        List<TComment> list = tCommentService.selectTCommentList(tComment);
        ExcelUtil<TComment> util = new ExcelUtil<TComment>(TComment.class);
        util.exportExcel(response, list, "学生评价数据");
    }

    /**
     * 获取学生评价详细信息
     */
    @RequiresPermissions("employment:comment:query")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(tCommentService.selectTCommentById(id));
    }






    /**
     * 新增学生评价
     */
//    @RequiresPermissions("employment:comment:add")
    @Log(title = "学生评价", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TComment tComment)
    {
        tComment.setCommentTime(new Date());
        return toAjax(tCommentService.insertTComment(tComment));
    }

    /**
     * 修改学生评价
     */
    @RequiresPermissions("employment:comment:edit")
    @Log(title = "学生评价", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TComment tComment)
    {
        return toAjax(tCommentService.updateTComment(tComment));
    }

    /**
     * 删除学生评价
     */
    @RequiresPermissions("employment:comment:remove")
    @Log(title = "学生评价", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(tCommentService.deleteTCommentByIds(ids));
    }
}
